﻿using System;
using System.Collections.Generic;

using System.Text;
using HZ.Data;

using System.Data;
using System.Data.SqlClient;
using HZ.BidSystem.Model;
namespace HZ.BidSystem.DAL
{
    public class DAL_CompeteTimeConfig
    {
        public static IList<CompeteTimeConfig> GetCompeteTimeConfigByProjectid(int project)
        {
            string sql = string.Format("SELECT * FROM dbo.TB_CompeteTimeConfig WHERE ProjectId = {0}", project);

            return DAL_Helper.CommonFillList<CompeteTimeConfig>(DbHelperFactory.Create().ExecuteTable(sql));
        }

        public static int SetCompeteTimeConfig(IList<CompeteTimeConfig> list)
        {
            int projectid = list[0].ProjectId.Value;
            var idb = DbHelperFactory.Create();
            try
            {
                idb.BeginTrans();
                string sql = string.Format("DELETE FROM dbo.TB_CompeteTimeConfig WHERE ProjectId = {0}", projectid);
                idb.ExecuteNonQuery(sql);

                foreach (var item in list)
                {
                    DAL_Helper.InsertModel(item, idb);
                }

                idb.CommitTrans();
                return 1;
            }
            catch (Exception ee)
            {

                idb.RollTrans();

                HZ.Common.log4netManager.LogDebug("DAL_CompeteTimeConfig", ee.Message, ee);
                return 0;
#if DEBUG
                throw;
#endif
            }
        }
    }
}
